package com.woniuxy.businessassembly.controller;

import com.woniuxy.businessassembly.model.HotelRoom;
import com.woniuxy.businessassembly.service.IHotelRoomService;
import com.woniuxy.common.Result;
import com.woniuxy.hotel.api.RoomManagement;
import com.woniuxy.hotel.form.RoomForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author kevin kwok
 * @create 2021-05-25 10:10
 */
@RestController
@Slf4j
public class RoomManagementController implements RoomManagement {

    @Resource
    private IHotelRoomService roomService;

    @Override
    public Result addRoom(RoomForm roomForm) {
        log.info("酒店新增房间{}",roomForm);
        HotelRoom hotelRoom = new HotelRoom();
        BeanUtils.copyProperties(roomForm,hotelRoom);
        int i = roomService.addNewRoom(hotelRoom);
        return new Result(true,"新增成功",i);
    }

    @Override
    public Result deleteRoom(Integer roomId) {
        log.info("删除酒店房间{}",roomId);
        int i = roomService.deleteRoom(roomId);
        return new Result(true,"删除成功",i);
    }

    @Override
    public Result modifyRoom(Integer roomId, RoomForm roomForm) {
        log.info("修改酒店房间信息{}{}",roomId,roomForm);
        HotelRoom hotelRoom = new HotelRoom();
        BeanUtils.copyProperties(roomForm,hotelRoom);
        int i = roomService.modifyRoom(hotelRoom, roomId);
        return new Result(true,"修改成功",i);
    }

    @Override
    public Result queryAllRooms() {
        log.info("查询所有酒店房间");
        List<HotelRoom> hotelRooms = roomService.queryAllRooms();
        return new Result(true,"查询成功",hotelRooms);
    }

    @Override
    public Result queryAllRoomsByFeature(String roomFeature) {
        log.info("根据酒店特色进行查询{}",roomFeature);
        List<HotelRoom> hotelRooms = roomService.queryByFeature(roomFeature);
        return new Result(true,"查询成功",hotelRooms);
    }

    @Override
    public Result queryAllRoomsByType(String roomType) {
        log.info("根据酒店类型进行查询{}",roomType);
        List<HotelRoom> hotelRooms = roomService.queryByType(roomType);
        return new Result(true,"查询成功",hotelRooms);
    }
}
